<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>大题号管理</title>
    <link rel="stylesheet" href="__PUBLIC__/BeginnerAdmin/plugins/layui/css/layui.css" media="all"/>

</head>
<body>

<!--管理大题号-->
<div id="TitleNumberManageID" style="margin:5px 5px auto 5px;" class="layui-form">
    <blockquote class="layui-elem-quote">
        <button class="layui-btn layui-btn-sm" id="addQid">
            <i class="layui-icon">&#xe608;</i> 添加题目
        </button>
    </blockquote>
    <table id="TitleNumberTable" lay-filter="TitleNumberTable"></table>

</div>

<script src="__PUBLIC__/BeginnerAdmin/plugins/layui/layui.js"></script>
<script src="__PUBLIC__/AmazeUI/assets/js/jquery-1.8.0.min.js"></script>
<script src="__PUBLIC__/editor/ckeditor.js"></script>

<script>

    layui.use(['layer', 'table', 'form'], function () {
        var  layer = layui.layer, table = layui.table, form = layui.form;

        $("#TitleNumberManageButton").on('click', function () {
            layer.open({
                type: 1,
                title: "管理题号",
                area: ['540px', '420px'],
                content: $('#TitleNumberManageID'),
                cancel: function (index, layero) {
                    layer.load(1);
                    window.location.reload(true);
                }
            });
        });
        $("#addQid").on('click', function () {
            layer.open({
                title: '添加题号',
                maxmin: false,
                type: 2,
                id: 1,
                content: "<{:U('TestQuestions/AddQIDUI',array('assignmentid'=>$assignmentid))}>",
                area: ['630px', '380px'],
                end: function (index, layero) {
                    settime();
                }
            });
        });
        var TitleNumberTable = table.render({
            elem: '#TitleNumberTable',
            url: "<{:U('TestQuestions/SelectTitleNumber')}>",
            method: 'post',
            size: 'sm',
            page: true,
            where: {assignmentid: "<{$assignmentid}>"},
            cols: [[
                {field: 'id', title: 'ID', checkbox: true}
                , {field: 'sequence', title: '排序', width: 80, edit: true, sort: true}
                , {field: 'title_explain', title: '说明'}
                , {fixed: 'right', width: 150, title: '操作', toolbar: '#barDemo'}
            ]]
        });


        table.on('tool(TitleNumberTable)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            console.log(obj);

            if (layEvent === 'delect') { //删除
                layer.confirm('真的删除行么', function (index) {
                    $.post('Admin_TestQuestions_DelectTitleNumber.html', {questionnumber: obj.data.id}, function (ret) {
                        if (ret.code == 200) {
                            layer.msg('删除成功' + ret.msg);
                            obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                        } else {
                            layer.alert(ret.msg);
                        }
                    }, 'json');
                    setTimeout('settime()', 1500);//延时执行，让人看得更清楚
                });
            } else if (layEvent === 'edit') { //编辑
                layer.open({
                    title: '修改题号',
                    maxmin: false,
                    type: 2,
                    id: 1,
                    content: "<{:U('TestQuestions/EditAddQIDUI')}>?examquestnum="+obj.data.id,
                    area: ['630px', '380px'],
                    end: function (index, layero) {
                        settime();
                    }
                });
            }
        });
    });
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon">&#xe640;</i>修改</a>
    <a class="layui-btn layui-btn-xs" lay-event="delect"><i class="layui-icon">&#xe640;</i>删除</a>
</script>
</body>
</html>